<!DOCTYPE html>
<html>
	<head th:include="/common/head :: head">
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
	</head>
	<body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="userName" class="layui-form-label">
                  <span class="x-red">*</span>登陆名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="userName" name="userName" required="" lay-verify="userName"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="nickName" class="layui-form-label">
                  <span class="x-red">*</span>昵称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="nickName" name="nickName" required="" lay-verify="nickName"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="mobile" class="layui-form-label">
                  <span class="x-red">*</span>手机
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="mobile" name="mobile" required="" lay-verify="phone"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="email" class="layui-form-label">
                  <span class="x-red">*</span>邮箱
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="email" name="email" required="" lay-verify="email"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="password" class="layui-form-label">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="firstPassword" name="password" required="" lay-verify="password"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="confirmPass" class="layui-form-label">
                  <span class="x-red">*</span>确认密码
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="confirmPass" name="confirmPass" required="" lay-verify="confirmPass"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
		    <label class="layui-form-label">性别</label>
		    <div class="layui-input-block">
		      <input type="radio" name="sex" value="1" title="男" checked="">
		      <input type="radio" name="sex" value="2" title="女">
		    </div>
		  </div>
         <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label"></label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">增加</button>
         </div>
      </form>
    </div>
  </body>
	<script>
		//表单验证对象
		var addFormData={};
		$(function(){
			initAddForm();
		})
		//初始化添加表单
		function initAddForm(){
			layui.use(['form','layer'],function(){
				$ = layui.jquery;
				var form = layui.form,
				layer = layui.layer;
				//验证规则
				form.verify({
					userName:function(value){
						if(value.length < 5){
					    	return '登录名至少得3个字符';
					  	}
					},
					nickName:function(value){
						if(value.length <3){
							return '昵称最少得三个字符';
						}
					},
					password: [/(.+){6,18}$/, '密码必须6到18位'],
					confirmPass: function(value){
					    if($('#firstPassword').val()!=$('#confirmPass').val()){
					        return '两次密码不一致';
					    }
					}
				});
				//监听提交
				form.on('submit(add)',function(data){
					console.log(data);
					//console.log(data.field);
					addFormData = data.field;
					addUser()
					return false;
				});
			});
		}
		//添加用户
		function addUser(){
			$.ajax({
				url:"/user/doAddUser",
				type:"post",
				data:{
					"userName":addFormData.userName,
					"nickName":addFormData.nickName,
					"mobile":addFormData.mobile,
					"email":addFormData.email,
					"password":addFormData.password,
					"sex":addFormData.sex
				},
				success:function(result){
					console.log(JSON.stringify(result));
					if(result.status==0){
						layer.msg(result.msg,function(){
							//关闭弹出层
							var index = parent.layer.getFrameIndex(window.name);
						    parent.layer.close(index);
						    //刷新当前页面
							//parent.location.replace(parent.location.href);
	                    });
					}else{
						layer.msg(result.msg);
					}
				}
			})
		}
	
	</script>












</html>